SNA Descritive Analysis from “Projeto Redes de Atenção às pessoas que consomem álcool e outras Drogas em Juiz de Fora-MG Brazil” - SNArRDJF
Here you can find a basic script to analysis data from SNArRDJF - this script was elaborated considering its use for orther matrix adjacency data from SNArRDJF - Here we are going to analyse:
########################## Basic Preparation ##### `#########################
rm(list = ls()) # removing previous objects to be sure that we don't have objects conflicts name
load("~/SNArRDJF/Robject/atividade_data.RData")
suppressMessages(library(RColorBrewer))
#suppressMessages(library(car))
#suppressMessages(library(xtable))
suppressMessages(library(igraph))
#suppressMessages(library(miniCRAN))
#suppressMessages(library(magrittr))
#suppressMessages(library(keyplayer))
suppressMessages(library(dplyr))
#suppressMessages(library(feather))
#suppressMessages(library(visNetwork))
#suppressMessages(library(knitr))
suppressMessages(library(DT))
#In order to get dinamic javascript object install those ones. If you get problems installing go to Stackoverflow.com and type your error to discover what to do. In some cases the libraries need to be intalled in outside R libs.
#devtools::install_github("wch/webshot")
#webshot::install_phantomjs()
set.seed(123)
#atividade<-simplify(atividade) #Simplify
How close an actor to all the other actors in network?
High closeness centrality - short communication path to others, minimal number of steps to reach others.
Answers the “Kevin Bacon” question:
How many steps are required to access every other vertex from a given vertex?
One practical implication of this metric: it helps you gauge how information might spread within your network, and who might be the best people to leverage if you need to make sure information gets around. Link here: http://www.tc.umn.edu/~alink/R-social-network-analysis.html
Closeness centrality can be defined as a measure of how far other nodes are from the node in question. Nodes with high closeness centrality are likely to be relatively efficient in receiving or transmitting information to/from distant parts of the social network.
Scores may be interpreted as arising from a reciprocal process in which the centrality of each actor is proportional to the sum of the centralities of those actors to whom he or she is connected.
In general, vertices with high eigenvector centralities are those which are connected to many other vertices which are, in turn, connected to many others (and so on). (The perceptive may realize that this implies that the largest values will be obtained by individuals in large cliques (or high-density substructures)
V(atividade)$incloseness <- closeness(atividade, mode = "in", weights = E(atividade)$atividade) %>% round(6)
V(atividade)$outcloseness <- closeness(atividade, mode = "out", weights = E(atividade)$atividade) %>% round(6)
V(atividade)$totalcloseness <- closeness(atividade, mode = "total", weights = E(atividade)$atividade) %>% round(4)
atividade_incloseness<- closeness(atividade, mode = "in", weights = E(atividade)$atividade) %>% round(6)
atividade_outcloseness<- closeness(atividade, mode = "out", weights = E(atividade)$atividade) %>% round(6)
atividade_totalcloseness<- closeness(atividade, mode = "total", weights = E(atividade)$atividade) %>% round(6)
summary(atividade_incloseness)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000290 0.0001280 0.0001290 0.0001272 0.0001300 0.0001350
sd(atividade_incloseness)
## [1] 1.070926e-05
V(atividade)$incloseness<-closeness(atividade, weights = E(atividade)$atividade, mode="in")
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$incloseness,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="in"),
edge.width=E(atividade)$weight/mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=closeness(atividade, weights = E(atividade)$atividade, mode="in")*10^5,
vertex.frame.color="black",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=(closeness(atividade, weights = E(atividade)$atividade, mode="in")+10^-5)*2000,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized and Colored In - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median In Closennes:%.4f\nSD In Closennes: %.5f",
median(closeness(atividade, mode="in", weights = E(atividade)$atividade)),
sd(closeness(atividade, mode="in", weights = E(atividade)$atividade))
)
)
summary(atividade_outcloseness)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000290 0.0005300 0.0007820 0.0006511 0.0008990 0.0011040
sd(atividade_outcloseness)
## [1] 0.0003428904
V(atividade)$outcloseness<-closeness(atividade, weights = E(atividade)$atividade, mode="out")
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$outcloseness,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="out"),
edge.width=E(atividade)$weight/2*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=closeness(atividade, weights = E(atividade)$atividade, mode="out")*10^4,
vertex.frame.color="white",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=closeness(atividade, weights = E(atividade)$atividade, mode="out")*200,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized and Colored OUT - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median OUT Closennes:%.4f\nSD OUT Closennes: %.5f",
median(closeness(atividade, mode="out", weights = E(atividade)$atividade)),
sd(closeness(atividade, mode="out", weights = E(atividade)$atividade))
)
)
summary(atividade_totalcloseness)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000029 0.001093 0.001225 0.001192 0.001342 0.001650
sd(atividade_totalcloseness)
## [1] 0.0002215581
V(atividade)$allcloseness<-closeness(atividade, weights = E(atividade)$atividade, mode="all")
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$allcloseness,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="all"),
edge.width=E(atividade)$weight/2*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=closeness(atividade, weights = E(atividade)$atividade, mode="all")*10^4,
vertex.frame.color="white",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=(closeness(atividade, weights = E(atividade)$atividade, mode="all")+0.00001)*200,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized and Colored all - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median all Closennes:%.4f\nSD all Closennes: %.5f",
median(closeness(atividade, mode="all", weights = E(atividade)$atividade)),
sd(closeness(atividade, mode="all", weights = E(atividade)$atividade))
)
)
V(atividade)$incloseness_n <- closeness(atividade, mode = "in",, weights = E(atividade)$atividade, normalized = T) %>% round(10)
V(atividade)$outcloseness_n <- closeness(atividade, mode = "out", normalized = T, weights = E(atividade)$atividade) %>% round(6)
V(atividade)$totalcloseness_n <- closeness(atividade, mode = "total", normalized = T, weights = E(atividade)$atividade) %>% round(6)
atividade_incloseness_n<- closeness(atividade, mode = "in", normalized = T, weights = E(atividade)$atividade) %>% round(6)
atividade_outcloseness_n<- closeness(atividade, mode = "out", normalized = T, weights = E(atividade)$atividade) %>% round(6)
atividade_totalcloseness_n<- closeness(atividade, mode = "total", normalized = T, weights = E(atividade)$atividade) %>% round(6)
summary(atividade_incloseness_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.005348 0.023760 0.023950 0.023650 0.024160 0.025080
sd(atividade_incloseness_n)
## [1] 0.001994514
V(atividade)$incloseness_n<-closeness(atividade, weights = E(atividade)$atividade, mode="in", normalized = T)
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$incloseness_n,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="in",normalized = T),
edge.width=E(atividade)$weight/10*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=(closeness(atividade, weights = E(atividade)$atividade, mode="in",normalized = T))*1000,
vertex.frame.color="black",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=closeness(atividade, weights = E(atividade)$atividade, mode="in",normalized = T)*10,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized Normalized In - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median In Closennes:%.4f\nSD In Closennes: %.5f",
median(closeness(atividade, mode="in", weights = E(atividade)$atividade, normalized = T)),
sd(closeness(atividade, mode="in", weights = E(atividade)$atividade, normalized = T))
)
)
###Closeness Normalized - OUT
summary(atividade_outcloseness_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.005348 0.098540 0.145400 0.121100 0.167300 0.205300
sd(atividade_outcloseness_n)
## [1] 0.06379751
V(atividade)$outcloseness_n<-closeness(atividade, weights = E(atividade)$atividade, mode="out", normalized = T)
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$outcloseness_n,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="out",normalized = T),
edge.width=E(atividade)$weight/10*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=(closeness(atividade, weights = E(atividade)$atividade, mode="out",normalized = T))*100,
vertex.frame.color="black",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=closeness(atividade, weights = E(atividade)$atividade, mode="out",normalized = T)*1.5,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized Normalized OUT - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median OUT Closennes:%.4f\nSD OUT Closennes: %.5f",
median(closeness(atividade, mode="out", weights = E(atividade)$atividade, normalized = T)),
sd(closeness(atividade, mode="out", weights = E(atividade)$atividade, normalized = T))
)
)
summary(atividade_totalcloseness_n)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.005348 0.203400 0.227900 0.221700 0.249700 0.306900
sd(atividade_totalcloseness_n)
## [1] 0.04121422
V(atividade)$allcloseness_n<-closeness(atividade, weights = E(atividade)$atividade, mode="all", normalized = T)
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$allcloseness_n,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "RdBu"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=closeness(atividade, weights = E(atividade)$atividade, mode="all",normalized = T),
edge.width=E(atividade)$weight/10*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=(closeness(atividade, weights = E(atividade)$atividade, mode="all",normalized = T))*100,
vertex.frame.color="black",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=closeness(atividade, weights = E(atividade)$atividade, mode="all",normalized = T)*1.5,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Closeness Degree Sized Normalized ALL - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median ALL Closennes:%.4f\nSD ALL Closennes: %.5f",
median(closeness(atividade, mode="all", weights = E(atividade)$atividade, normalized = T)),
sd(closeness(atividade, mode="all", weights = E(atividade)$atividade, normalized = T))
)
)
V(atividade)$incloseness_n <- closeness(atividade, weights = E(atividade)$atividade, mode = "in", normalized = T) %>% round(6)
V(atividade)$outcloseness_n <- closeness(atividade, weights = E(atividade)$atividade, mode = "out", normalized = T) %>% round(6)
V(atividade)$totalcloseness_n <- closeness(atividade, weights = E(atividade)$atividade, mode = "total", normalized = T) %>% round(6)
V(atividade)$atividade_centr_closeness<- centralization.closeness(atividade)$res
atividade_centr_closeness<- centralization.closeness(atividade)$res
atividade_centr_closeness_all<- centralization.closeness(atividade)
atividade_centr_closeness_all$centralization
## [1] 0.1023336
atividade_centr_closeness_all$theoretical_max
## [1] 185.0053
V(atividade)$atividade_centr_closeness<- centralization.closeness(atividade)$res
#Get Variable
V(atividade)$atividade_color_degree<-round(V(atividade)$atividade_centr_closeness,6)
#Creating brewer pallette
vertex_atividade_color_degree<-
colorRampPalette(brewer.pal(length(unique(
V(atividade)$atividade_color_degree)), "Spectral"))(
length(unique(V(atividade)$atividade_color_degree)))
#Saving as Vertex properties
V(atividade)$vertex_atividade_color_degree<-
vertex_atividade_color_degree[as.numeric(
cut(V(atividade)$atividade_color_degree,
breaks=length(unique(V(atividade)$atividade_color_degree))))]
set.seed(123)
#Plotting based only on degree measures
edge.start <- ends(atividade, es=E(atividade), names=F)[,1]
# Fixing ego
minC <- rep(-Inf, vcount(atividade))
maxC <- rep(Inf, vcount(atividade))
minC[1] <- maxC[1] <- 0
co <- layout_with_fr(atividade, niter=10^4, minx=minC, maxx=maxC,miny=minC, maxy=maxC, weights = E(atividade)$weight)
#PLotting
plot(atividade,
layout=co,
edge.color=V(atividade)$vertex_atividade_color_degree[edge.start],
edge.arrow.size=centralization.closeness(atividade)$res,
edge.width=E(atividade)$weight/10*mean(E(atividade)$weight),
edge.curved = TRUE,
vertex.color=V(atividade)$vertex_atividade_color_degree,
vertex.size=centralization.closeness(atividade)$res*100,
vertex.frame.color="black",
vertex.label.color="black",
vertex.label=get.vertex.attribute(atividade,"LABEL_COR"),
vertex.label.cex=centralization.closeness(atividade)$res,
vertex.label.dist=0,
rescale=F,
xlim=range(co[,1]),
ylim=range(co[,2])
)
axis(1)
axis(2)
#Solving Problems with legend rendering
a<-V(atividade)$atividade_color_degree
b<-V(atividade)$vertex_atividade_color_degree
c<-table(a,b)
d<-as.data.frame(c)
e<-subset(d, d$Freq>0)
e<-e[order(e$a,decreasing=T),]
f<-t(e$a)
g<-t(e$b)
#Adding Legend
legend(x=range(co[,1])[2],
y=range(co[,2])[2],
legend=as.character(f),
pch=21,
col = "#777777",
pt.bg=as.character(g),
pt.cex=2,
bty="n",
ncol=1,
lty=1,
cex = .3)
#Adding Title
title("Network Centralization Closeness - 27_ATIVIDADE", sub = "Source: from authors ")
text(
x=range(co[,1])[1],
y=range(co[,2])[1],
labels = sprintf(
"Median Centralization Closeness:%.4f\nSD Centralization Closeness: %.5f",
median(centralization.closeness(atividade)$res),
sd(centralization.closeness(atividade)$res)
)
)
atividade_incloseness<- closeness(atividade, weights = E(atividade)$atividade, mode = "in") %>% round(6)
atividade_outcloseness<- closeness(atividade, weights = E(atividade)$atividade, mode = "out") %>% round(6)
atividade_totalcloseness<- closeness(atividade, weights = E(atividade)$atividade, mode = "total") %>% round(6)
atividade_incloseness_n<- closeness(atividade,weights = E(atividade)$atividade, mode = "in", normalized = T) %>% round(6)
atividade_outcloseness_n<- closeness(atividade,weights = E(atividade)$atividade, mode = "out", normalized = T) %>% round(6)
atividade_totalcloseness_n<- closeness(atividade,weights = E(atividade)$atividade, mode = "total", normalized = T) %>% round(6)
atividade_centr_closeness <- centralization.closeness(atividade)$res %>% round(6)
atividade_df_closseness <- data.frame(
atividade_incloseness,
atividade_outcloseness,
atividade_totalcloseness,
atividade_incloseness_n,
atividade_outcloseness_n,
atividade_totalcloseness_n,
atividade_centr_closeness) %>% round(6)
#Adding type
atividade_df_closseness <-cbind(atividade_df_closseness, V(atividade)$LABEL_COR)
#Adding names
names(atividade_df_closseness) <- c("In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized", "Total Closeness Normalized","Centralization Closeness","Type")
#Ordering Variables
atividade_df_closseness<-atividade_df_closseness[c("Type","In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized","Total Closeness Normalized", "Centralization Closeness")]
datatable(atividade_df_closseness, filter = 'top')
aggdata_mean <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=mean, na.rm=TRUE)
names(aggdata_mean) <- c("Group","Type","In Closeness(M)", "Out Closeness(M)", "Total Closeness(M)","In Closeness Normalized(M)", "Out Closeness Normalized(M)", "Total Closeness Normalized(M)","Centralization Closeness(M)")
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
aggdata_sd <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=sd, na.rm=TRUE)
names(aggdata_sd) <- c("Group","Type","In Closeness(SD)", "Out Closeness(SD)", "Total Closeness(SD)","In Closeness Normalized(SD)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(SD)", "Centralization Closeness(SD)")
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
#Merging mean and standart deviation
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(6) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Closeness(M)", "In Closeness(SD)", "Out Closeness(M)", "Out Closeness(SD)", "Total Closeness(M)","Total Closeness(SD)","In Closeness Normalized(M)", "In Closeness Normalized(SD)", "Out Closeness Normalized(M)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(M)","Total Closeness Normalized(SD)", "Centralization Closeness(M)","Centralization Closeness(SD)")]
datatable(total_table, filter = 'top')
atividade_df_closseness <- data.frame(
atividade_incloseness,
atividade_outcloseness,
atividade_totalcloseness,
atividade_incloseness_n,
atividade_outcloseness_n,
atividade_totalcloseness_n,
atividade_centr_closeness) %>% round(6)
#Adding type
atividade_df_closseness <-cbind(atividade_df_closseness, V(atividade)$TIPO1)
#Adding names
names(atividade_df_closseness) <- c("In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized", "Total Closeness Normalized","Centralization Closeness","Type")
#Ordering Variables
atividade_df_closseness<-atividade_df_closseness[c("Type","In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized","Total Closeness Normalized", "Centralization Closeness")]
datatable(atividade_df_closseness, filter = 'top')
aggdata_mean <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=mean, na.rm=TRUE)
names(aggdata_mean) <- c("Group","Type","In Closeness(M)", "Out Closeness(M)", "Total Closeness(M)","In Closeness Normalized(M)", "Out Closeness Normalized(M)", "Total Closeness Normalized(M)","Centralization Closeness(M)")
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
aggdata_sd <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=sd, na.rm=TRUE)
names(aggdata_sd) <- c("Group","Type","In Closeness(SD)", "Out Closeness(SD)", "Total Closeness(SD)","In Closeness Normalized(SD)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(SD)", "Centralization Closeness(SD)")
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
#Merging mean and standart deviation
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(6) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Closeness(M)", "In Closeness(SD)", "Out Closeness(M)", "Out Closeness(SD)", "Total Closeness(M)","Total Closeness(SD)","In Closeness Normalized(M)", "In Closeness Normalized(SD)", "Out Closeness Normalized(M)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(M)","Total Closeness Normalized(SD)", "Centralization Closeness(M)","Centralization Closeness(SD)")]
datatable(total_table, filter = 'top')
atividade_df_closseness <- data.frame(
atividade_incloseness,
atividade_outcloseness,
atividade_totalcloseness,
atividade_incloseness_n,
atividade_outcloseness_n,
atividade_totalcloseness_n,
atividade_centr_closeness) %>% round(6)
#Adding type
atividade_df_closseness <-cbind(atividade_df_closseness, V(atividade)$TIPO2)
#Adding names
names(atividade_df_closseness) <- c("In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized", "Total Closeness Normalized","Centralization Closeness","Type")
#Ordering Variables
atividade_df_closseness<-atividade_df_closseness[c("Type","In Closeness", "Out Closeness", "Total Closeness","In Closeness Normalized", "Out Closeness Normalized","Total Closeness Normalized", "Centralization Closeness")]
datatable(atividade_df_closseness, filter = 'top')
aggdata_mean <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=mean, na.rm=TRUE)
names(aggdata_mean) <- c("Group","Type","In Closeness(M)", "Out Closeness(M)", "Total Closeness(M)","In Closeness Normalized(M)", "Out Closeness Normalized(M)", "Total Closeness Normalized(M)","Centralization Closeness(M)")
#Removing Type variable
aggdata_mean<-aggdata_mean[,-c(2)]
aggdata_sd <-aggregate(atividade_df_closseness, by=list(atividade_df_closseness$Type), FUN=sd, na.rm=TRUE)
names(aggdata_sd) <- c("Group","Type","In Closeness(SD)", "Out Closeness(SD)", "Total Closeness(SD)","In Closeness Normalized(SD)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(SD)", "Centralization Closeness(SD)")
#Removing Type variable
aggdata_sd<-aggdata_sd[,-c(2)]
#Merging mean and standart deviation
total_table <- merge(aggdata_mean,aggdata_sd,by="Group")
#Rounding
Group<-total_table[,c(1)] #Keeping group
total_table<-total_table[,-c(1)] %>% round(6) #Rouding
total_table<-cbind(Group,total_table) #Binding toghter
#Organizing Variabels
total_table<-total_table[c("Group","In Closeness(M)", "In Closeness(SD)", "Out Closeness(M)", "Out Closeness(SD)", "Total Closeness(M)","Total Closeness(SD)","In Closeness Normalized(M)", "In Closeness Normalized(SD)", "Out Closeness Normalized(M)", "Out Closeness Normalized(SD)", "Total Closeness Normalized(M)","Total Closeness Normalized(SD)", "Centralization Closeness(M)","Centralization Closeness(SD)")]
datatable(total_table, filter = 'top')
save.image("~/SNArRDJF/Robject/atividade_data.RData")